﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Utility.DataSystem
{
	public class FieldEventSettingObject : SettingObject<FieldEventSetting>
	{
		public string key;
		public string showName;
		public int contextFlags;
		public int allowedContextFlags;
		public int debugMode = 0;
		public bool isContextLocal;
	}

	public class FieldEventSetting : Setting<FieldEventSettingObject>
	{
		public string Key => SettingObject.key;
		public string ShowName => SettingObject.showName;
		public int ContextFlags => SettingObject.contextFlags;
		public int AllowedContextFlags => SettingObject.allowedContextFlags;
		public int DebugMode => SettingObject.debugMode;
		public bool IsContextLocal => SettingObject.isContextLocal;

		public void InvokeEvent (IDataFieldContext context)
		{
			var e = new FieldEvent (this, context);
			context.OnEvent (e);
		}
	}

	public struct FieldEvent
	{
		public FieldEvent (FieldEventSetting setting, IDataFieldContext sourceContext, IList<DataValue> parameters, int targetEntities = 0)
		{
			Setting = setting;
			SourceContext = sourceContext;
			Parameters = parameters;
			TargetEntities = targetEntities;
		}
		public FieldEvent (FieldEventSetting setting, IDataFieldContext sourceContext, int targetEntities = 0) : this (setting, sourceContext, null, targetEntities)
		{
		}

		public FieldEventSetting Setting { get; }
		public IDataFieldContext SourceContext { get; }
		public int TargetEntities { get; }
		public IList<DataValue> Parameters { get; }

		public bool HasParam => (Parameters?.Count ?? 0) > 0;
	}
}